
#include "MoveEffect.h"

MoveEffect::MoveEffect(RenderableEntity* _entity, float _fDuration, bool _bEnabled, bool _bLoop, Vector2 _vInitPos, Vector2 _vEndPos, eEaseMode _eMode) : SpriteEffect(_entity, _fDuration, _bEnabled, _bLoop)
{
    m_vInitPos = _vInitPos;
    m_vEndPos = _vEndPos;
	m_bHasInit = true;
    m_bTranslation = false;
    m_oCurve = NULL;
    m_eEaseMode = _eMode;
}

MoveEffect::MoveEffect(RenderableEntity* _entity, float _fDuration, bool _bEnabled, bool _bLoop, Vector2 _vEndPos, bool _bTranslation, eEaseMode _eMode) : SpriteEffect(_entity, _fDuration, _bEnabled, _bLoop)
{
    if(_bTranslation)
    {
        m_bTranslation = true;
        m_vTranslation = _vEndPos;
    }
    else 
    {
        m_vEndPos = _vEndPos;
    }
	m_bHasInit = false;
    m_oCurve = NULL;
    m_eEaseMode = _eMode;
}

MoveEffect::MoveEffect(RenderableEntity* _entity, float _fDuration, bool _bEnabled, bool _bLoop, BezierCurve *_oCurve) : SpriteEffect(_entity, _fDuration, _bEnabled, _bLoop)
{
    m_oCurve = _oCurve;
	m_bHasInit = true;
    m_bTranslation = false;
}

void MoveEffect::updateEffect(float _fPerc)
{
	if(m_oCurve)
		m_entity->setPosition(m_oCurve->computeV(_fPerc));
	else
		m_entity->setPosition(m_vInitPos + (m_vEndPos - m_vInitPos) * _fPerc);
}

void MoveEffect::enableEffect(bool _bValue)
{
    if(_bValue)
    {
        if(m_bTranslation)
        {
            m_vInitPos = m_entity->getPosition();
            m_vEndPos = m_vInitPos + m_vTranslation;
        }
        else if(!m_bHasInit)
        {
            m_vInitPos = m_entity->getPosition();
        }
    }
}
